package com.kfc.crazy4week.api.common.bean;

import com.kfc.crazy4week.api.constant.ResultStatusCode;
import lombok.Getter;
import lombok.Setter;

/**
 * @author niXuechao
 * @date 2021/5/10
 */

@Setter
@Getter
public class Result<T> {
    private Integer code;
    private String msg;
    private T data;

    public Result() {
    }

    public Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static Result<?> success() {
        Result<?> result = new Result<>();
        result.setCode(ResultStatusCode.SUCCESS);
        result.setMsg("success");
        return result;
    }

    public static <E> Result<E> success(E data) {
        Result<E> result = new Result<>();
        result.setCode(ResultStatusCode.SUCCESS);
        result.setMsg("success");
        result.setData(data);
        return result;
    }

    public static Result<?> fail() {
        Result<?> result = new Result<>();
        result.setCode(ResultStatusCode.FAIL);
        result.setMsg("fail");
        return result;
    }

    public static Result<?> fail(String msg) {
        Result<?> result = new Result<>();
        result.setCode(ResultStatusCode.FAIL);
        result.setMsg(msg);
        return result;
    }

    public static <T> Result<T> failWithData(String msg, T data) {
        Result<T> result = new Result<>();
        result.setCode(ResultStatusCode.FAIL);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static Result<?> fail(int code, String msg) {
        Result<?> result = new Result<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }


}
